google.load("visualization", "1", {packages:["corechart"]});
function drawChart() {
	from_date = jQuery('#from_date').val();
	to_date = jQuery('#to_date').val();
	jQuery.post(SITE_URL + 'admin/dashboard/invoice_data', {from_date: from_date, to_date: to_date},function(res){
		/*
		var data = google.visualization.arrayToDataTable([
          	['Year', 'Sales', 'Expenses'],
          	['2004',  1000,      400],
          	['2005',  1170,      460],
          	['2006',  660,       1120],
          	['2007',  1030,      540]
          	  ]);
		*/
		 var data = new google.visualization.DataTable();
		 data.addColumn('string', res.x);
		 data.addColumn('number', res.y);
		 data.addRows(res.data);
		 var options = {
      			title: res.title
		 };

		 var chart = new google.visualization.LineChart(document.getElementById('invoice_chart'));
		 chart.draw(data, options);
	}, 'json');
}

jQuery(document).ready(function(){
	drawChart();
	jQuery("#from_date").datepicker({dateFormat: 'yy-mm-dd'});
	jQuery("#to_date").datepicker({dateFormat: 'yy-mm-dd'});
	jQuery('#update_invoice_chart').click(function(){
		drawChart();
	});
});